package com.backend.mzyf.Utils;

import org.springframework.util.ResourceUtils;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ResourceUtil {

    public List<String> getUrls(String fileName) {
        try {
            List<String> result = new ArrayList<String>();
            String encoding = "utf-8";
            File file = new File(ResourceUtils.getURL("classpath:")
                    .getPath() + "conf/" + fileName + ".txt");
            if (file.isFile() && file.exists()) { //判断文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file), encoding);//考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    result.add(lineTxt);
                }
                read.close();
                return result;
            } else {
                System.out.println("找不到指定的文件");
            }
        } catch (Exception e) {
            System.out.println("读取文件内容出错");
            e.printStackTrace();
        }
        return null;
    }


}
